<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="com.wlcorp.forcazamis.domain.system.Staff" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="com.wlcorp.forcazamis.domain.system.Department" %>
<%@ page import="com.wlcorp.forcazamis.domain.system.Role" %>
<%@ page import="com.wlcorp.forcazamis.domain.baseinfo.Depot" %>
<%@ page import="com.wlcorp.forcazamis.sys.util.AppConstant" %>

<%
	Staff staff = (Staff)request.getAttribute("staff");
	List staffList = (List)request.getAttribute("staffList");
	List departmentList = (List)request.getAttribute("departmentList");
	List roleList = (List)request.getAttribute("roleList");
	List depotList = (List)request.getAttribute("depotList");
%>
<html>
<head>
	<title>员工信息更新</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta http-equiv="Pragma" content="no-cache"><meta http-equiv="Cache-Control" content="no-cache"><meta http-equiv="Expires" content="0">
	<link href="${pageContext.request.contextPath}/css/css.css" rel=stylesheet>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/button_css.css" type="text/css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/form_css.css" type="text/css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/table_css.css" type="text/css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/pagetitle_css.css" type="text/css">
	<script language="javascript" src="${pageContext.request.contextPath}/script/validator.js"></script>
	<script language="javascript" src="${pageContext.request.contextPath}/script/calendartime.js"></script>
	<script type="text/javascript">
		function doSave(){
			if(!fieldIsNotEmpty(document.forms["staffForm"].staffName)){
				return;
			}
			if(!fieldIsNotEmpty(document.forms["staffForm"].staffCode)){
				return;
			}
			if(!fieldIsNotEmpty(document.forms["staffForm"].tmpPassword)){
				return;
			}
			if(!fieldIsNotEmpty(document.forms["staffForm"].rePassword)){
				return;
			}
			if(!fieldIsNotEmpty(document.forms["staffForm"].roleId)){
				return;
			}
			if(!fieldIsNotEmpty(document.forms["staffForm"].departmentId)){
				return;
			}
			if(!fieldValidateByRegexp(document.forms["staffForm"].email,REGEXP_EMAIL)){
				return;
			}
			if(!fieldValidateByRegexp(document.forms["staffForm"].secEmail,REGEXP_EMAIL)){
				return;
			}
			if(!fieldValidateByRegexp(document.forms["staffForm"].phone,REGEXP_INTEGER)){
				return;
			}
			if(!fieldValidateByRegexp(document.forms["staffForm"].zipCode,REGEXP_ZIPCODE)){
				return;
			}
			if(document.forms["staffForm"].tmpPassword.value != document.forms["staffForm"].rePassword.value){
				alert("两次输入的密码不一致！");
				return;
			}
			document.forms["staffForm"].submit();
		}
		function goback(){
			window.location = "${pageContext.request.contextPath}/system/staffManager.do?method=staffManager";
		}
		var flag = true;
		var tmpOptions = new Array();
		function managerSelect(value){
			if(value.length < 1 && flag){
				return;
			}
			var managerSelect = document.getElementById("managerId");
			var options = managerSelect.options;
			if(flag){
				for(i = 0; i < options.length;i++){
					tmpOptions[tmpOptions.length] = options[i];
				}
				flag = false;
			}
			if(value.length < 1 && !flag){
				options.length = 0;
				for(i = 0; i < tmpOptions.length;i++){
					managerSelect.add(tmpOptions[i]);
				}
				return;
			}
			var optionArray = new Array();
			for(i = 0; i < tmpOptions.length;i++){
				if(tmpOptions[i].text.indexOf(value) > -1){
					optionArray[optionArray.length] = tmpOptions[i];
				}
			}
			options.length = 0;
			for(i = 0; i < optionArray.length;i++){
				managerSelect.add(optionArray[i]);
			}
		}
	</script>
</head>
<body>
<form name="staffForm" method="POST" action="${pageContext.request.contextPath}/system/staffManager.do?method=modifyStaff">
<input type="hidden" name="staffId" value="${staff.staffId}"/>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="30">
	<tr> 
	  <td width="22" class="page_titlebar_head">&nbsp;</td>
	  <td class="page_titlebar_bg" width="981">员工编辑</td>
	</tr>
</table>
<center>
<table width="80%" class="InputFrameMain" cellspacing="0" cellpadding="0" border="0" height="100">
  <tr class="InputFrameLine">
  		<td colspan="4" class="table_unfold_titlebar_small_bg">&nbsp;&nbsp;<b>员工基本信息编辑</b></td>
  </tr>
  <tr class="InputFrameLine">
        <td class="table_label" width="20%" id="staffName_TEXT">员工姓名</td>
		<td width="30%">&nbsp;<input class="input" type="text" name="staffName" value="${staff.staffName}" style="width:150px" maxlength="20"/></td>
		<td class="table_label" width="20%" id="nname_TEXT">中文妮称</td>
		<td width="30%">&nbsp;<input class="input" type="text" name="nname" value="${staff.nname}" style="width:150px" maxlength="20"/></td>
  </tr>
  <tr class="InputFrameLine">
        <td class="table_label" width="20%" id="ename_TEXT">英文姓名</td>
		<td width="30%">&nbsp;<input class="input" type="text" name="ename" value="${staff.ename}" style="width:150px" maxlength="20"/></td>
		<td class="table_label" width="20%" id="enname_TEXT">英文妮称</td>
		<td width="30%">&nbsp;<input class="input" type="text" name="enname" value="${staff.enname}" style="width:150px" maxlength="20"/></td>
  </tr>
  <tr class="InputFrameLine">
  		<td class="table_label" width="20%" id="staffCode_TEXT">工号</td>
		<td width="30%">&nbsp;<input class="input" type="text" name="staffCode" value="${staff.staffCode}" style="width:150px" maxlength="20"/></td>
		<td class="table_label" width="20%" id="tmpPassword_TEXT">密码</td>
		<td width="30%">&nbsp;<input class="input" type="password" name="tmpPassword" value="${staff.tmpPassword}" style="width:150px" maxlength="20"/></td>
  </tr>
  <tr class="InputFrameLine">
        <td class="table_label" width="20%" id="managerId_TEXT">上司</td>
		<td width="30%">&nbsp;
			<select name="managerId" style="width:100px">
				<option value="">--选择--</option>
				<%
					for(Iterator iter = staffList.iterator();iter.hasNext();){
						Staff tmpStaff = (Staff)iter.next();
						if(tmpStaff.getStaffId().equals(staff.getStaffId())){
							continue;
						}
				%>
				<option value="<%=tmpStaff.getStaffId()%>" <%if(null != staff.getManager() && tmpStaff.getStaffId().equals(staff.getManager().getStaffId())){out.print("selected");}%>><%=tmpStaff.getStaffName()%></option>
				<%}%>
			</select>
			<input type="text" name="managerTxt" value="" style="width:100px" onchange="managerSelect(this.value)"/>
		</td>
		<td class="table_label" width="20%" id="rePassword_TEXT">确认密码</td>
		<td width="30%">&nbsp;<input class="input" type="password" name="rePassword" value="${staff.tmpPassword}" style="width:150px" maxlength="20"/></td>
  </tr>
  <tr class="InputFrameLine">
        <td class="table_label" width="20%" id="gender_TEXT">性别</td>
		<td width="30%">&nbsp;<select name="gender" style="width:100px">
			<option value="<%=AppConstant.GENDER_MALE%>" <%if(null != staff.getGender() && AppConstant.GENDER_MALE == staff.getGender().intValue()){out.print("selected");}%>>男</option>
			<option value="<%=AppConstant.GENDER_FEMALE%>" <%if(null != staff.getGender() && AppConstant.GENDER_FEMALE == staff.getGender().intValue()){out.print("selected");}%>>女</option>
		</select>
		</td>
		<td class="table_label" width="20%" id="state_TEXT">状态</td>
		<td width="30%">&nbsp;<select name="state" style="width:100px">
			<option value="<%=AppConstant.STAFF_STATE_INACTIVE%>" <%if(null != staff.getState() && AppConstant.STAFF_STATE_INACTIVE == staff.getState().intValue()){out.print("selected");}%>>在职</option>
			<option value="<%=AppConstant.STAFF_STATE_NOT_INACTIVE%>" <%if(null != staff.getState() && AppConstant.STAFF_STATE_NOT_INACTIVE == staff.getState().intValue()){out.print("selected");}%>>不在职</option>
		</select>
		</td>
  </tr>
  <tr class="InputFrameLine">
        <td class="table_label" width="20%" id="roleId_TEXT">角色</td>
		<td width="30%">&nbsp;
			<select name="roleId" style="width:100px">
				<option value="">--选择--</option>
				<%
					for(Iterator iter = roleList.iterator();iter.hasNext();){
						Role role = (Role)iter.next();
				%>
				<option value="<%=role.getRoleId()%>" <%if(null != staff.getRole() && role.getRoleId().equals(staff.getRole().getRoleId())){out.print("selected");}%>><%=role.getRoleName()%></option>
				<%}%>
			</select>
		</td>
		<td class="table_label" width="20%" id="departmentId_TEXT">部门</td>
		<td width="30%">&nbsp;
			<select name="departmentId" style="width:100px">
				<option value="">--选择--</option>
				<%
					for(Iterator iter = departmentList.iterator();iter.hasNext();){
						Department department = (Department)iter.next();
				%>
				<option value="<%=department.getDepartmentId()%>" <%if(null != staff.getDepartment() && department.getDepartmentId().equals(staff.getDepartment().getDepartmentId())){out.print("selected");}%>><%=department.getDepartmentName()%></option>
				<%}%>
			</select>
		</td>
  </tr>
  <tr class="InputFrameLine">
        <td class="table_label" width="20%" id="email_TEXT">电子邮件</td>
		<td width="30%">&nbsp;<input class="input" type="text" name="email" value="${staff.email}" style="width:150px" maxlength="20"/></td>
		<td class="table_label" width="20%" id="phone_TEXT">电话</td>
		<td width="30%">&nbsp;<input class="input" type="text" name="phone" value="${staff.phone}" style="width:150px" maxlength="20"/></td>
  </tr>
  <tr class="InputFrameLine">
        <td class="table_label" width="20%" id="secEmail_TEXT">备用电子邮件</td>
		<td width="30%">&nbsp;<input class="input" type="text" name="secEmail" value="${staff.secEmail}" style="width:150px" maxlength="20"/></td>
		<td class="table_label" width="20%" id="mobile_TEXT">手机</td>
		<td width="30%">&nbsp;<input class="input" type="text" name="mobile" value="${staff.mobile}" style="width:150px" maxlength="20"/></td>
  </tr>
  <tr class="InputFrameLine">
        <td class="table_label" width="20%" id="email_TEXT">生日</td>
		<td width="30%">&nbsp;<input class="input" type="text" name="birthday" value="${staff.birthday}" onClick="setDay(this);" readOnly/></td>
		<td class="table_label" width="20%" id="zipCode_TEXT">邮编</td>
		<td width="30%">&nbsp;<input class="input" type="text" name="zipCode" value="${staff.zipCode}" style="width:150px" maxlength="20"/></td>
  </tr>
  <tr class="InputFrameLine">
        <td class="table_label" width="20%" id="depotId_TEXT">所属仓库</td>
		<td width="80%" colspan="3">&nbsp;
			<select name="depotId" style="width:100px">
				<option value="">--选择--</option>
				<%
					for(Iterator iter = depotList.iterator();iter.hasNext();){
						Depot depot = (Depot)iter.next();
				%>
				<option value="<%=depot.getDepotId()%>" <%if(null != staff.getDepot() && depot.getDepotId().equals(staff.getDepot().getDepotId())){out.print("selected");}%>><%=depot.getDepotName()%></option>
				<%}%>
			</select>
		</td>
  </tr>
  <tr class="InputFrameLine">
        <td class="table_label" width="20%" id="address_TEXT">地址</td>
		<td width="80%" colspan="3">&nbsp;<input class="input" type="text" name="address" value="${staff.address}" style="width:300px" maxlength="60"/></td>
  </tr>
  
  <tr class="InputFrameLine">
  	<td width="100%" colspan="4" align="center"><input type="button" class="button_common" name="save_button" value="保存" onclick="javascript:doSave()">
  	<input type="button" class="button_common" name="goback_button" value="返回" onclick="javascript:history.go(-1);"></td>
  </tr>
</table>
</center>
</form>
${message}
</body>
</html>
